﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//请先添加引用

namespace Tuan.DAL
{
    public class Question
    {
		public Question()
		{ }
        #region 成员方法
        /// <summary>
        /// 得到相应商品ID的相应问题
        /// </summary>
        public string SelectQuestion(int ProID, int Seq)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 3 * from Review where ");
            strSql.Append("ProductID=@ProID ");
            strSql.Append("order by ReviewID asc ");
            SqlParameter[] parameters = {
					new SqlParameter("@ProID", SqlDbType.Int,4)
            };
            parameters[0].Value = ProID;
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            return ds.Tables[0].Rows[Seq-1]["Body"].ToString();
        }

        /// <summary>
        /// 得到相应商品ID的相应问题的答案
        /// </summary>
        public string SelectAnswer(int ProID, int Seq)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 3 * from Review where ");
            strSql.Append("ProductID=@ProID");
            strSql.Append(" order by ReviewID asc");
            SqlParameter[] parameters = {
					new SqlParameter("@ProID", SqlDbType.Int,4)
            };
            parameters[0].Value = ProID;
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            return ds.Tables[0].Rows[Seq-1]["Reply"].ToString();
        }

        /// <summary>
        /// 得到相应商品ID的相应问题的链接
        /// </summary>
        public string SelectQuestLink(int ProID, int Seq)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 3 * from Review where ");
            strSql.Append("ProductID=@ProID");
            strSql.Append(" order by ReviewID asc");
            SqlParameter[] parameters = {
					new SqlParameter("@ProID", SqlDbType.Int,4)
            };
            parameters[0].Value = ProID;
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            return ds.Tables[0].Rows[Seq-1]["QuestLink"].ToString();
        }

        /// <summary>
        /// 得到相应商品ID的问题答案
        /// </summary>
        public string SelectQuestNum(int ProID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(*) as num from Review where ");
            strSql.Append("ProductID=@ProID");
            SqlParameter[] parameters = {
					new SqlParameter("@ProID", SqlDbType.Int,4)
            };
            parameters[0].Value = ProID;
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            return ds.Tables[0].Rows[0]["num"].ToString();
        }
        #endregion
    }
}
